/* GUI CONVERTED from soasmt.p (converter v1.76) Thu Dec  5 05:03:10 2002 */
/* soasmt.p - CREDIT ACTION STATUS MAINT                                      */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.14.1.14 $                                                     */
/*V8:ConvertMode=Maintenance                                                  */
/* Revision: 5.0      LAST MODIFIED: 03/09/90   BY: ftb                       */
/* Revision: 5.0      LAST MODIFIED: 10/17/90   BY: pml *D106*                */
/* Revision: 6.0      LAST MODIFIED: 04/05/91   BY: bjb *D507*                */
/* Revision: 7.3      LAST MODIFIED: 01/26/93   BY: tjs *G599*                */
/* Revision: 7.3      LAST MODIFIED: 10/25/93   BY: tjs *GG58*                */
/* Revision: 7.4      LAST MODIFIED: 02/21/94   BY: tjs *H188*                */
/* Revision: 7.4      LAST MODIFIED: 09/21/94   BY: ljm *GM77*                */
/* Revision: 8.5      LAST MODIFIED: 12/18/94   BY: mwd *J034*                */
/* Revision: 7.4      LAST MODIFIED: 07/27/95   BY: taf *G0V8*                */
/* Revision: 7.4      LAST MODIFIED: 07/27/95   BY: taf *G0XY*                */
/* Revision: 7.3      LAST MODIFIED: 07/27/95   BY: taf *G19Z*                */
/* Revision: 8.5      LAST MODIFIED: 07/27/95   BY: taf *J053*                */
/* REVISION: 8.5      LAST MODIFIED: 07/19/96   BY: taf *J0ZZ*                */
/* Revision: 8.6      LAST MODIFIED: 10/22/96   BY: *K004* Stephane Collard   */
/* Revision: 8.6      LAST MODIFIED: 07/11/97   BY: *K0G6* Arul Victoria      */
/* Revision: 8.6      LAST MODIFIED: 08/07/97   BY: *H1CW* Ajit Deodhar       */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 04/23/98   BY: *L00L* EvdGevel           */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* REVISION: 8.6E     LAST MODIFIED: 07/15/98   BY: *L024* Steve Goeke        */
/* REVISION: 8.6E     LAST MODIFIED: 09/27/99   BY: *L0J4* Satish Chavan      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 02/20/98   BY: *N06R* Denis Tatarik      */
/* REVISION: 9.1      LAST MODIFIED: 08/23/00   BY: *N0ND* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 10/18/00   BY: *M0V0* Ravikumar. K       */
/* Revision: 1.14.1.8       BY: Katie Hilbert     DATE: 04/01/01  ECO: *P002* */
/* Revision: 1.14.1.9       BY: Ellen Borden      DATE: 07/09/01  ECO: *P007* */
/* Revision: 1.14.1.10      BY: Ashwini G.        DATE: 01/10/02  ECO: *L194* */
/* Revision: 1.14.1.11    BY: Jean Miller       DATE: 05/15/02  ECO: *P05V* */
/* $Revision: 1.14.1.14 $   BY: Laurene Sheridan  DATE: 11/01/02  ECO: *P09M* */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdtitle.i "2+ "}

define new shared variable convertmode as character no-undo
   initial "MAINT".

define variable open_amt like ar_amt label "Open Amount".
define variable line_amt like ar_amt.
define variable bill_cust like ad_name.
define variable sold_cust like ad_name.
define variable ship_cust like ad_name.
define new shared variable rndmthd     like rnd_rnd_mthd.
define new shared variable so_recno    as recid.
define new shared variable new_order      like mfc_logical initial no.
define new shared variable due_date_range like mfc_logical initial yes.
define new shared variable date_range     like sod_due_date.
define new shared variable date_range1    like sod_due_date.
define new shared variable display_trail  like mfc_logical initial no.
define new shared variable undo_trl2      like mfc_logical.

define new shared frame sotot.
define variable oldcurr    like so_curr.
define variable vl-cr-card like mfc_logical
   label "CC Details" no-undo.

define variable l_so_db    like global_db             no-undo.
define variable err-flag   as integer                 no-undo.

define variable lg_calling_app as character no-undo.
define   variable l_nontaxable_lbl as character format "x(12)" .
define temp-table tmp_db no-undo
   field tmp_db_name like si_db.

{mfsotrla.i "NEW"}

{etdcrvar.i new}
{etvar.i &new = new}
{etrpvar.i &new = new}

/* ASSIGN ORIGINAL FORMAT TO _OLD VARIABLES */
assign
   nontax_old = nontaxable_amt:format
   taxable_old = taxable_amt:format
   line_tot_old = line_total:format
   disc_old     = disc_amt:format
   trl_amt_old = so_trl1_amt:format
   tax_amt_old = tax_amt:format
   ord_amt_old = ord_amt:format
   container_old = container_charge_total:format
   line_charge_old = line_charge_total:format.

assign oldcurr = "".

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
so_bill       colon 18
   so_cust       colon 47
   bill_cust     no-label at 20
   sold_cust     no-label at 50
   so_ship       colon 47
   ship_cust     no-label at 50 skip
   cm_cr_rating  colon 18 cm_balance   colon 47
   cm_cr_hold    colon 18 cm_cr_limit  colon 47 skip
   so_ord_date   colon 18 so_po        colon 47
   so_conf_date  colon 18
   so_due_date   colon 18 open_amt     colon 47
   so_req_date   colon 18 skip(1)
   vl-cr-card    colon 18
   so_stat       colon 18
   so_cr_term    colon 18 so_cr_init skip(1)
 SKIP(.4)  /*GUI*/
with frame b side-labels attr-space width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-b-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
 RECT-FRAME-LABEL:HIDDEN in frame b = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame b =
  FRAME b:HEIGHT-PIXELS - RECT-FRAME:Y in frame b - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME b = FRAME b:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame b:handle).


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
space(1)
   so_nbr
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   view frame a.
   view frame b.

   prompt-for so_nbr with frame a
   editing:

      /* FIND NEXT/PREVIOUS RECORD */
      {mfnp.i so_mstr so_nbr so_nbr so_nbr so_nbr so_nbr}
      
      if recno <> ? then do:
         display so_nbr with frame a.
  
       

         line_amt = 0.

         if (oldcurr <> so_curr) or (oldcurr = "") then do:

            {gprunp.i "mcpl" "p" "mc-get-rnd-mthd"
               "(input  so_curr,
                 output rndmthd,
                 output mc-error-number)" }
            if mc-error-number <> 0 then do:
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
               undo, retry.
            end.

            {socurfmt.i}
            assign oldcurr = so_curr.

         end.

         assign
            maint = no
            date_range = low_date
            date_range1 = hi_date
            so_recno = recid(so_mstr).

         /* DETERMINE ord_amt */
         {gprun.i ""hksosotrld.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         if so_curr = base_curr then
            open_amt = ord_amt.
         else do:
            {gprunp.i "mcpl" "p" "mc-curr-conv"
               "(input  so_curr,
                 input  base_curr,
                 input  so_ex_rate,
                 input  so_ex_rate2,
                 input  ord_amt,
                 input  true,  /* ROUND */
                 output open_amt,
                 output mc-error-number)" }
            if mc-error-number <> 0 then do:
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
            end.
         end.

         find ad_mstr where ad_addr = so_ship no-lock no-error.
         if available ad_mstr then
            ship_cust = ad_name.
         else
            ship_cust = "".

         find ad_mstr where ad_addr = so_cust no-lock no-error.
         sold_cust = ad_name.

         find cm_mstr where cm_addr = so_bill no-lock no-error.
         find ad_mstr where ad_addr = so_bill no-lock no-error.
         bill_cust = ad_name.

         if available cm_mstr then do:
            display
               so_bill
               so_cust
               bill_cust
               sold_cust
               so_ship
               ship_cust
               cm_cr_rating
               cm_balance
               cm_cr_hold
               cm_cr_limit
               so_po
               so_ord_date
               open_amt
               so_due_date
               so_req_date
               so_conf_date
               so_stat
               no @ vl-cr-card
               so_cr_term
               so_cr_init
            with frame b attr-space width 80.
         end.
         open_amt = 0.
      end. /* IF RECNO <> ? */

   end. /* prompt-for */

   find so_mstr where so_nbr = input so_nbr no-error.
   if not available so_mstr then do:
      {pxmsg.i &MSGNUM=609 &ERRORLEVEL=3} /* Sales Order does not exist */
      next-prompt so_nbr with frame a.
      undo, retry.
   end.
   if available so_mstr  AND lookup(so_site,global_user_site) = 0  then do:
      {pxmsg.i &MSGNUM=2328 &ERRORLEVEL=3} 
      next-prompt so_nbr with frame a.
      undo, retry.
   end.  
/*   if available so_mstr  AND so_conf_date =?  then do:
      {pxmsg.i &MSGNUM=621 &ERRORLEVEL=3} 
      next-prompt so_nbr with frame a.
      undo, retry.
   end.  
          In api mode check that the application ID that owns the SO
            is the one that is trying to modify it. If we are not in API
            mode the mgqqapp.i will return blank as the calling app.
*/
   {mgqqapp.i "lg_calling_app"}

   if (lg_calling_app <> ?) and (lg_calling_app <> "") then do:
      if (so_app_owner <> lg_calling_app) then do:
          /* Cannot change status, SO is owned by another application.*/
          {pxmsg.i &MSGNUM=3402 &ERRORLEVEL=3}
          undo,return.
      end.
   end.

   for each sod_det where sod_nbr      =  so_nbr
                      and sod_btb_type <> "01"
                      and sod_btb_po   <> ""
   no-lock break by sod_btb_po:

      if not first-of(sod_btb_po) then next.

      find po_mstr where po_nbr  = sod_btb_po and
                         po_xmit = "5"
      no-lock no-error.

      if available po_mstr then leave.

   end. /* For each sod_det */

   if available po_mstr then do:
      {pxmsg.i &MSGNUM=2807 &ERRORLEVEL=3}
      /* Cannot modify SO with pending changes */
      next-prompt so_nbr with frame a.
      undo, retry.
   end.

   if (oldcurr <> so_curr) or (oldcurr = "") then do:

      {gprunp.i "mcpl" "p" "mc-get-rnd-mthd"
         "(input  so_curr,
           output rndmthd,
           output mc-error-number)" }
      if mc-error-number <> 0 then do:
         {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
         undo, retry.
      end.

      {socurfmt.i}
      oldcurr = so_curr.
   end.

   assign
      line_amt = 0
      maint = no
      date_range = low_date
      date_range1 = hi_date
      so_recno = recid(so_mstr).

   /* DETERMINE ord_amt */
    {gprun.i ""hksosotrld.p""}  
 
 
/*GUI*/ if global-beam-me-up then undo, leave.


   /* ORD_AMT IS IN DOCUMENT CURRENCY AND IS ROUNDED PER THAT CURR */
   /* IF DOC CURR AND BASE CURR ARE NOT THE SAME THEN CALCULATE ORD*/
   /* AMOUNT USING THE BASE EXCHANGE RATE AND ROUND PER BASE CURR  */
   if so_curr = base_curr then
      open_amt = ord_amt.
   else do:
      {gprunp.i "mcpl" "p" "mc-curr-conv"
         "(input  so_curr,
           input  base_curr,
           input  so_ex_rate,
           input  so_ex_rate2,
           input  ord_amt,
           input  true,  /* ROUND */
           output open_amt,
           output mc-error-number)" }
      if mc-error-number <> 0 then do:
         {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
         undo, retry.
      end.
   end.

   find ad_mstr where ad_addr = so_ship no-lock no-error.
   if available ad_mstr then
      ship_cust = ad_name.
   else
      ship_cust = "".

   find ad_mstr where ad_addr = so_cust no-lock.
   sold_cust = ad_name.

   find ad_mstr where ad_addr = so_bill no-lock.
   bill_cust = ad_name.

   find cm_mstr where cm_addr = so_bill no-lock.

   display
      so_bill
      so_cust
      bill_cust
      sold_cust
      so_ship
      ship_cust
      cm_cr_rating
      cm_balance
      cm_cr_hold
      cm_cr_limit
      so_po
      so_ord_date
      open_amt
      so_due_date
      so_req_date
      so_conf_date
      so_stat
      no @ vl-cr-card
      so_cr_term so_cr_init
   with frame b attr-space width 80.

   {gprun.i ""gpsiver.p"" "(input so_site,
                            input ?,
                            output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   if return_int = 0 then do:
      /* User does not have access to this site */
      {pxmsg.i &MSGNUM=2710 &ERRORLEVEL=3 &MSGARG1=so_site}
      undo mainloop, retry.
   end.

   setb:
   do on error undo, retry with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.


      vl-cr-card = no.
      display vl-cr-card with frame b.

      set
         vl-cr-card  when (can-find (socc_mstr where
                           socc_nbr = so_nbr))
         so_stat
         so_cr_term
         so_cr_init
      with frame b.
      IF so_stat<>'HD' and GLOBAL_userid<>'mfg' THEN so_user2=GLOBAL_userid.
      if so_cr_terms <> ""
      then do:

         find first ct_mstr where ct_code = so_cr_terms
         no-lock no-error.

         if not available ct_mstr then do:
            /* CREDIT TERM CODE MUST EXIST OR BE BLANK */
            {pxmsg.i &MSGNUM=840 &ERRORLEVEL=3}
            next-prompt so_cr_term with frame b.
            undo setb, retry setb.
         end. /* IF NOT AVAILABLE CT_MSTR */

      end. /* IF SO_CR_TERMS <> "" */

      /*Run Credit Card Maintenance*/
      if vl-cr-card then
         {gprun.i ""soccmt.p"" "(input so_nbr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* SETB */

   {gprun.i ""sobtbcrh.p"" "(input so_nbr, input so_stat)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   l_so_db = global_db.

   for each sod_det
      fields(sod_btb_po sod_btb_type sod_nbr sod_site)
      where sod_nbr = so_nbr
   no-lock:

      for first si_mstr
         fields(si_db si_site)
         where si_site = sod_site and
         si_db   <> l_so_db no-lock:
      end. /* FOR FIRST si_mstr */
      if available si_mstr
      then do:
         if not (can-find (first tmp_db
                           where tmp_db_name = si_db))
         then do:
            create tmp_db.
            tmp_db_name = si_db.
         end. /* IF NOT CAN-FIND FIRST tmp_db ... */
      end. /* IF AVAILABLE si_mstr */

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR EACH sod_det */

   for each tmp_db:
/*GUI*/ if global-beam-me-up then undo, leave.


      {gprun.i ""gpalias3.p""
         "(tmp_db_name,
           output err-flag)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /*SOASMT01.P CALLED TO PROPAGATE CREDIT DETAILS */
      /* TO REMOTE DATABASE */
      if err-flag = 0 or
         err-flag = 9
      then do:
         {gprun.i ""soasmt01.p""
            "(input so_nbr,
              input so_stat,
              input so_cr_init,
              input so_cr_terms)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end. /* if err-flag .. */

      {gprun.i ""gpalias3.p""
         "(l_so_db,
           output err-flag)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR EACH tmp_db */

   /* ADDED FOLLOWING SO RMA STAT STAYS IN SYNC */
   find first rma_mstr where rma_nbr = so_nbr and rma_prefix = "C"
   exclusive-lock no-error.

   if available rma_mstr then rma_stat = so_stat.

end. /* MAINLOOP: REPEAT: */

